<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        function Node(val) {
            this.val = val;
            this.left = null;
            this.right = null;
        }
        var a = new Node(1)
        var b = new Node(2)
        var c = new Node(3)
        var d = new Node(null)
        var e = new Node(5)
        a.left = b
        a.right = c
        b.right = e


        var binaryTreePaths = function (root) {
           let res = []
           function traverse (node, curPath) {
            debugger
                if (!node.left && !node.right) {
                    curPath += node.val
                    res.push(curPath)
                    return
                }
                curPath += node.val + '->'
                node.left && traverse(node.left, curPath)
                node.right && traverse(node.right, curPath)
           }
           traverse(root, '')
           return res
        }
        console.log(binaryTreePaths(a));
    </script>
</body>

</html>